import request from '@/utils/request'; 
import { da } from 'element-plus/es/locales.mjs'; 


// 删除用户接口
export function deleteUser(data) {
    return request({
        url: '/user/delete',
        method: 'delete',
        data: data
    }).then(response => {
        console.log('deleteUser 接口响应:', response);
        if (response.code === "000") {
            return response;
        } else {
            console.error('deleteUser 调用失败:', response.statusText);
            throw new Error(`非 000 状态码: ${response.status}`);
        }
    }).catch(error => {
        console.error('deleteUser 请求失败:', error);
        throw error;
    });
}

// 根据名称查询医生接口
export function queryDoctorsByName(params) {
    return request({
        url: '/user/queryDoctorsByName',
        method: 'get',
        params: params
    }).then(response => {
        console.log('queryDoctorsByName 接口响应:', response);
        if (response.code === "000") {
            return response;
        } else {
            console.error('queryDoctorsByName 调用失败:', response.statusText);
            throw new Error(`非 000 状态码: ${response.code}`);
        }
    }).catch(error => {
        console.error('queryDoctorsByName 请求失败:', error);
        throw error;
    });
}

// 根据名称查询患者接口
export function queryPatientsByName(params) {
    return request({
        url: '/user/queryPatientsByName',
        method: 'get',
        params: params
    }).then(response => {
        console.log('queryPatientsByName 接口响应:', response);
        if (response.code === "000") {
            return response;
        } else {
            console.error('queryPatientsByName 调用失败:', response.statusText);
            throw new Error(`非 000 状态码: ${response.code}`);
        }
    }).catch(error => {
        console.error('queryPatientsByName 请求失败:', error);
        throw error;
    });
}

// 更新患者信息接口
export function updatePatient(data) {
    return request({
        url: '/user/updatePatient',
        method: 'put',
        data: data
    }).then(response => {
        console.log('updatePatient 接口响应:', response);
        if (response.code === "000") {
            return response;
        } else {
            console.error('updatePatient 调用失败:', response.statusText);
            throw new Error(`非 000 状态码: ${response.code}`);
        }
    }).catch(error => {
        console.error('updatePatient 请求失败:', error);
        throw error;
    });
}

// 更新医生信息接口
export function updateDoctor(data) {
    return request({
        url: '/user/updateDoctor',
        method: 'put',
        data: data
    }).then(response => {
        console.log('updateDoctor 接口响应:', response);
        if (response.code === "000") {
            return response;
        } else {
            console.error('updateDoctor 调用失败:', response.statusText);
            throw new Error(`非 000 状态码: ${response.code}`);
        }
    }).catch(error => {
        console.error('updateDoctor 请求失败:', error);
        throw error;
    });
}



// 更新医生信息接口
export function updateUser(data) {
    return request({
        url: '/user/updateUser',
        method: 'put',
        data: data
    }).then(response => {
        console.log('updateUser 接口响应:', response);
        if (response.code === "000") {
            return response;
        } else {
            console.error('updateDoctor 调用失败:', response.statusText);
            throw new Error(`非 000 状态码: ${response.code}`);
        }
    }).catch(error => {
        console.error('updateDoctor 请求失败:', error);
        throw error;
    });
}
